package polymorphic;

/**
 * @ClassName Test
 * @Description TODO
 * @Author hp
 * @Date 2021/6/15 16:39
 * @Version 1.0
 **/
public class Test {
    public static void main(String[] args) {
        Animals animals = new Dog();//向上转型
        animals.eat();

        //判断是否等于new的类
        if(animals instanceof Dog){
            //向下转型
            ((Dog)animals).protectHome();
            /*Dog dog =(Dog)animals;
            dog.protectHome();*/
        }

        if(animals instanceof Cat){
            Cat cat =(Cat) animals;
            cat.catchMouse();
        }
    }
}
